package com.yidu.t299.dao.zzy;

import com.yidu.t299.domain.zzy.ClassLog;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ClassLogMapper {
    /**
     * 根据校区编号删除该校区信息
     * @param classLogId 校区编号
     * @return 影响的行数(返回1则为成功)
     */
    @Delete({
        "delete from class_log" +
        " where classlog_id = #{classLogId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer classLogId);

    /**
     * 添加校区信息
     * @param record 校区对象
     * @return 影响的行数(返回1则为成功)
     */
    @Insert({
        "insert into class_log (classlog_id, classlog_date,classlog_context,class_id)" +
        " values (#{classLogId,jdbcType=INTEGER}, #{classLogDate,jdbcType=VARCHAR}," +
                " #{classLogContext,jdbcType=VARCHAR}, #{classId,jdbcType=INTEGER})"
    })
    int insert(ClassLog record);

    /**
     * 根据校区编号查询指定的信息
     * @param classLogId 校区编号
     * @return 校区对象
     */
    @Select({
        "select" +
        " classlog_id, classlog_date,classlog_context,class_id" +
        " from class_log" +
        " where classlog_id = #{classLogId,jdbcType=INTEGER}"
    })
    @Results(id = "ClassLogMap",value = {
            @Result(id = true,column = "classlog_id",property = "classLogId"),
            @Result(column = "classlog_date",property = "classLogDate"),
            @Result(column = "classlog_context",property = "classLogContext"),
            @Result(column = "class_id",property = "classId"),
            @Result(column = "class_id", property = "aClass", javaType = Class.class
                    , one = @One(select = "com.yidu.t299.dao.zzy.ClasssMapper.selectByPrimaryKey"))
    })
    ClassLog selectByPrimaryKey(Integer classLogId);

    /**
     * 按条件分页查询校区数据集合
     * @param rows 每页的行数
     * @param page 页码
     * @param condition 条件参数
     * @return 校区对象集合
     */
    @Select("SELECT * FROM class_log cl  " +
            "JOIN class c " +
            "ON cl.class_id=c.class_id " +
            "where 1=1 ${condition} limit #{page},#{rows}")
    @Results({
            @Result(id = true,column = "classlog_id",property = "classLogId"),
            @Result(column = "classlog_date",property = "classLogDate"),
            @Result(column = "classlog_context",property = "classLogContext"),
            @Result(column = "class_id", property = "aClass", javaType = Class.class
                    , one = @One(select = "com.yidu.t299.dao.zzy.ClasssMapper.selectByPrimaryKey"))
    })
    List<ClassLog> selectByPage(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);

    /**
     * 按条件查询school表中数据行数
     * @param condition 条件参数
     * @return 数据行数
     */
    @Select("SELECT count(*) FROM class_log cl  " +
            "JOIN class c " +
            "ON cl.class_id=c.class_id " +
            "where 1=1 ${condition}")
    int selectCount(@Param("condition") String condition);

    /**
     * 根据校区信息修改其数据
     * @param record 校区对象
     * @return 影响的行数(返回1则为成功)
     */
    @Update({
        "update class_log",
        " set classlog_date = #{classLogDate,jdbcType=VARCHAR},classlog_context = #{classLogContext,jdbcType=VARCHAR},class_id = #{classId,jdbcType=INTEGER}",
        " where classlog_id = #{classLogId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(ClassLog record);
}